import time
import traceback
import random

from selenium.webdriver import Keys, ActionChains

from MyTools.myutils import TestUtils
import pdb

cookie_str = 'rememberMe=true; sidebarStatus=0; Admin-Expires-In=1440; Library-Admin-Expires-In=1440; username=%E9%99%88%E5%B8%85; password=Ab4SSzMGMii0jqZJtfCF+55+/NtkxBjt1f9COY0Dzxz5htfEEuWhXIHeX6Yui6AX+Pbg1G0H4pI4fpNNrn4pCg==; integrated-platform-Token=6dc3c25c-6f1d-452f-898d-38c89ca1722e; SECKEY_ABVK=xIs6ZHyHiaPNl7nulH3xZyQaS3t/7EASp0Tz1d4Ruvo%3D; BMAP_SECKEY=kntq7QmppuAfIl9yo8A11MermcejygEtg1otBJ-X4rXyP30nAit-AxmW8Gjb7h4tbcqgQ6f2UKwvbasqLadj9ulM_4R-HLA71NqDI8biTv2Zr0OkOCTNKjJ29j8lSQLaoUC64h0nio-HGhiUU5cipx04X-y8lZr6tlosvvarQRgOEn24X-tFBN17brEZcp_J'
# self.click_when_visible('')
sj_number = str(random.randint(1, 1000))

class MytestClass(TestUtils):

    def test_zjxt(self):

        self.open("http://10.0.0.75:811/index")
        time.sleep(3)
        try:
            actions = ActionChains(self.driver)
            self.cookie_adder(cookie_str)
            self.check_status(self)
            self.maximize_window()

            ######################## 课堂管理 ########################
            self.open("http://10.0.0.75:811/zjmanage")
            self.click_when_visible('#app > div > div > div.z1-frame-leftlg.el-col.el-col-24.el-col-xs-24.el-col-sm-6.el-col-md-4.el-col-lg-4.el-col-xl-4 > div > div:nth-child(2) > div')
            self.click_when_visible('#app > div > div > div.z1-frame-rigthflg.el-col.el-col-24.el-col-xs-24.el-col-sm-18.el-col-md-20.el-col-lg-20.el-col-xl-20 > div > div.z1-frame > div.el-row > div.el-col.el-col-24.el-col-xs-24.el-col-sm-18.el-col-md-20.el-col-lg-20.el-col-xl-20 > div > div.z1-table-layout-tool > div > div:nth-child(1) > button')
            self.send_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.main-container.hasTagsView > section > div > div > micro-app > micro-app-body > div.el-drawer__wrapper > div > div > section > div.drawer-container > div > div.right > div > form > div:nth-child(1) > div > div > input',"自学课程"+sj_number)
            self.sendkey_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.main-container.hasTagsView > section > div > div > micro-app > micro-app-body > div.el-drawer__wrapper > div > div > section > div.drawer-container > div > div.right > div > form > div:nth-child(2) > div > div > div > input','enter')
            time.sleep(1)
            self.sendkey_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.main-container.hasTagsView > section > div > div > micro-app > micro-app-body > div.el-drawer__wrapper > div > div > section > div.drawer-container > div > div.right > div > form > div:nth-child(2) > div > div > div > input','down')
            actions.send_keys(Keys.ENTER).perform()


            self.send_keys('input[type="file"].el-upload__input', 'C:/Users/Administrator.SC-201811252126/Pictures/bdj.jpg')
            self.send_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.main-container.hasTagsView > section > div > div > micro-app > micro-app-body > div.el-drawer__wrapper > div > div > section > div.drawer-container > div > div.right > div > form > div:nth-child(4) > div > div > textarea',"八段锦，是我国较为经典的传统养生功法之一，注重身心合一，有着丰富的历史内涵和文化底蕴。八段锦主要有八个基本动作，具有柔和缓慢、圆活连贯、松紧结合、动静相兼、神与形合、气寓其中之特点，其练习音乐轻快舒缓、柔和连绵，能消除疲劳、调节心境。八段锦把人的形体活动、呼吸吐纳、心理调节三者相结合，具有调息脏腑、运行气血、畅通经脉、强健筋骨、凝心安神之功。因其动作简单、容易掌握，属于中低强度的有氧运动，又具有一定的防病治病作用，深受中老年人的欢迎。2003年，国家体育总局将八段锦重新编排，并向全国推广，一套仅需短短十二分钟即可完成。"+sj_number)
            self.click_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.main-container.hasTagsView > section > div > div > micro-app > micro-app-body > div.el-drawer__wrapper > div > div > section > div.drawer-footer > button.z1-button.z1-button-primary.z1-button-small')

            self.send_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.main-container.hasTagsView > section > div > div > micro-app > micro-app-body > div.el-drawer__wrapper > div > div > section > div.drawer-container > div > div.right > div > div.itemBox > div.item_top > div > div > input','课件'+sj_number)
            self.click_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.main-container.hasTagsView > section > div > div > micro-app > micro-app-body > div.el-drawer__wrapper > div > div > section > div.drawer-container > div > div.right > div > div.itemBox > div.item_top > div > div > span > span > button')

            self.click_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.main-container.hasTagsView > section > div > div > micro-app > micro-app-body > div.el-drawer__wrapper > div > div > section > div.drawer-container > div > div.right > div > div.itemBox > div.item_add > div:nth-child(1)')
            time.sleep(1)
            self.click_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.main-container.hasTagsView > section > div > div > micro-app > micro-app-body > div.el-dialog__wrapper > div > div.el-dialog__body > div > div > div.el-col.el-col-24.el-col-xs-24.el-col-sm-6.el-col-md-4.el-col-lg-4.el-col-xl-6 > div > div.z1-frame-left-button.z1-tree.ly-flex-1 > div.el-tree.el-tree--highlight-current > div:nth-child(2) > div.el-tree-node__content > span.ly-flex-align-center.ly-flex-pack-justify.ly-flex-1 > div')
            actions.send_keys(Keys.TAB).perform()
            actions.send_keys(Keys.TAB).perform()
            actions.send_keys(Keys.TAB).perform()
            actions.send_keys(Keys.TAB).perform()
            actions.send_keys(Keys.SPACE).perform()
            self.click_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.main-container.hasTagsView > section > div > div > micro-app > micro-app-body > div.el-dialog__wrapper > div > div.el-dialog__footer > div > div:nth-child(2) > button')
            self.clear_when_visible()
            self.send_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.main-container.hasTagsView > section > div > div > micro-app > micro-app-body > div:nth-child(9) > div > div.el-dialog__body > div > div:nth-child(1) > div.el-input.el-input--medium.el-input-group.el-input-group--append > input','1')
            self.send_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.main-container.hasTagsView > section > div > div > micro-app > micro-app-body > div:nth-child(9) > div > div.el-dialog__body > div > div:nth-child(2) > div.el-input.el-input--medium.el-input-group.el-input-group--append > input','2')
            self.send_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.main-container.hasTagsView > section > div > div > micro-app > micro-app-body > div:nth-child(9) > div > div.el-dialog__body > div > div:nth-child(3) > div.el-input.el-input--medium.el-input-group.el-input-group--append > input','3')
            self.click_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.main-container.hasTagsView > section > div > div > micro-app > micro-app-body > div.el-drawer__wrapper > div > div > section > div.drawer-container > div > div.right > div > div.itemBox > div.item_add > div:nth-child(2) > div')
            self.click_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.main-container.hasTagsView > section > div > div > micro-app > micro-app-body > div:nth-child(10) > div > div.el-dialog__body > div > div > div.el-col.el-col-24.el-col-xs-24.el-col-sm-18.el-col-md-20.el-col-lg-20.el-col-xl-18 > div > div > div.z1-table-layout-content > div.el-table.el-table--fit.el-table--enable-row-hover.el-table--enable-row-transition.el-table--small > div.el-table__body-wrapper.is-scrolling-none > table > tbody > tr > td.el-table_36_column_304.el-table-column--selection.el-table__cell > div > label > span > span')
            self.click_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.main-container.hasTagsView > section > div > div > micro-app > micro-app-body > div:nth-child(10) > div > div.el-dialog__footer > div > div:nth-child(2) > button')
            self.click_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.main-container.hasTagsView > section > div > div > micro-app > micro-app-body > div.el-drawer__wrapper > div > div > section > div.drawer-footer > button.z1-button.z1-button-primary.z1-button-small')

            #选择永久有效,立即上架,开启推荐、拖动进度、倍速播放
            self.click_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.main-container.hasTagsView > section > div > div > micro-app > micro-app-body > div.el-drawer__wrapper > div > div > section > div.drawer-container > div > div.right > div > form > div:nth-child(2) > div > div > div:nth-child(1) > label > div')
            self.click_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.main-container.hasTagsView > section > div > div > micro-app > micro-app-body > div.el-drawer__wrapper > div > div > section > div.drawer-container > div > div.right > div > form > div:nth-child(3) > div > div > div:nth-child(1) > label > div')
            self.click_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.main-container.hasTagsView > section > div > div > micro-app > micro-app-body > div.el-drawer__wrapper > div > div > section > div.drawer-container > div > div.right > div > form > div:nth-child(4) > div > div > div:nth-child(1) > label > div')
            self.click_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.main-container.hasTagsView > section > div > div > micro-app > micro-app-body > div.el-drawer__wrapper > div > div > section > div.drawer-container > div > div.right > div > form > div:nth-child(5) > div > div > div:nth-child(1) > label > div')
            self.click_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.main-container.hasTagsView > section > div > div > micro-app > micro-app-body > div.el-drawer__wrapper > div > div > section > div.drawer-container > div > div.right > div > form > div:nth-child(6) > div > div > div:nth-child(1) > label > div')

            self.click_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.main-container.hasTagsView > section > div > div > micro-app > micro-app-body > div.el-drawer__wrapper > div > div > section > div.drawer-footer > button.z1-button.z1-button-primary.z1-button-small')

            pdb.set_trace()#断点
        except Exception as e:
            tb_str = traceback.format_exception(etype=type(e), value=e, tb=e.__traceback__)
            print(f"抱歉，出现错误：{str(e)}")
            print("".join(tb_str))  # 显示详细的错误追踪信息，包括在哪一行代码触发的错误